<template>
	<view>
		
		<view class="hospital">
			<view class="txt">
				<view class="name">
					{{info.hospitalName}}
				</view>
				<view class="star">
					<image v-for="(i) in info.level" :key="i" src="../../../static/star.png" mode=""></image>
				</view>
				<view class="brief">
					{{info.brief}}
				</view>
			</view>
			
			<view class="img">
				<image :src="info.imgUrl" mode=""></image>
			</view>
		</view>
		
	</view>
</template>
<!-- 门诊预约类型 hospital_category_type 普通诊 2 -->
<!-- 门诊预约类型 hospital_category_type 专家诊 1 -->

<script>
	import {getHospitalInfo} from '../../../api/hospitalApi.js'
	import {mockHospitalInfo} from '../../../mock/hospital.js';
	import{baseurl} from '../../../api/request.js';
export default {
	data() {
		return {
			indicatorDots: true,
			autoplay: true,
			interval: 2000,
			duration: 500,
			id:null,
			info:{},
			
		}
	},
	methods: {
		async getInfo(id){
			let res2 = await getHospitalInfo(id);
			// console.log("info的res2==>",res2);
			let obj = {};
			if(res2.code == 200){
				obj = res2.data;
				obj.brief = this.removeHtmlTags(obj.brief);
				obj.imgUrl = baseurl + obj.imgUrl;
			}else{
				obj = mockHospitalInfo().data.filter(item=>{
					// console.log("this.id:",this.id);
					// console.log("item.id:",item.id);
					return item.id == this.id;
				})[0];
				// console.log("obj====>",obj);
				obj.brief = this.removeHtmlTags(obj.brief);
			}
			
			// console.log('55555',obj);
			this.info = obj;
			// console.log("info:",this.info);
		},
		removeHtmlTags(text){//将html标签里的字符串取出
			// console.log("text:",text);
		    return text.replace(/<[^>]*>/g, '');
		}
	},
	onLoad: function (options) {
	  // options 中包含了通过 url 传递的参数
	  this.id = options.id;
	  console.log("获取到的id为：", this.id);
	  this.getInfo(this.id)
	},
	created(){
		
	}
	
}
</script>

<style lang="scss">
	.hospital{
		width: 100%;
		box-sizing: border-box;
		padding: 20rpx;
	}
	.hospital .img{
		width: 100%;
		
		& image{
			width: 100%;
			border-radius: 20rpx;
		}
	}
	.hospital .txt{
		width: 100%;
	}
	.hospital .txt .name{
		font-size: 18px;
		line-height: 24px;
		color: #000;
		font-weight: 600;
		text-align: center;
	}
	.hospital .txt .star{
		width: 100%;
		height: 30rpx;
		margin: 20rpx 0;
		display: flex;
		justify-content: center;
		& image{
			width: 30rpx;
			height: 100%;
			margin: 0 10rpx;
		}
	}
	.hospital .txt .brief{
		width: 100%;
		text-indent: 2em;
		line-height: 20px;
		margin-bottom: 20rpx;
	}
	
	

</style>
